import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsEnum, IsInt, IsNotEmpty, IsNumber, IsObject, IsOptional, IsString } from "class-validator";
import { ArticleContentType } from "../article/article-content/article-content.entity";
import { SurveyType } from "../survey/survey.entity";
import { Transform, Type } from "class-transformer";
import { CommonStatus } from "~/common/entity/common.entity";

export class ArticleLogDto {
  @ApiProperty({ description: '文章ID', example: 1 })
  @IsInt()
  @IsNotEmpty()
  @Type(() => Number)
  articleId: number;

  @ApiProperty({ description: '文章类型', example: ArticleContentType.MEDICAL_KNOWLEDGE, enum: ArticleContentType })
  @IsEnum(ArticleContentType)
  @IsNotEmpty()
  articleType: ArticleContentType;

  @ApiProperty({ description: '阅读时长（秒）', example: 120, default: 0 })
  @IsNumber()
  @IsOptional()
  @Type(() => Number)
  readDuration: number = 0;

  @ApiProperty({ description: '分类ID', example: 1, required: false })
  @IsInt()
  @IsOptional()
  @Type(() => Number)
  categoryId?: number;
}

export class SurveyLogDto {
  @ApiProperty({ description: '问卷ID', example: '1' })
  @IsString()
  @IsNotEmpty()
  surveyId: string;

	@ApiProperty({ description: '问卷完成状态', example: CommonStatus.YES, enum: CommonStatus, default: CommonStatus.NO })
	@IsEnum(CommonStatus)
	@IsOptional()
	@Type(() => Number)
	isFinish: CommonStatus = CommonStatus.YES;

  @ApiProperty({ description: '问卷完成时长（秒）', example: 300, default: 0 })
  @IsNumber()
  @IsOptional()
  @Type(() => Number)
  duration: number = 0;

  @ApiProperty({ description: '问卷得分', example: 85, default: 0 })
  @IsNumber()
  @IsOptional()
  @Type(() => Number)
  score: number = 0;

  @ApiProperty({ description: '用户回答的JSON字符串', example: '{"q1": "A", "q2": "B"}', default: '{}' })
  @IsString()
  @IsOptional()
  answers: string = '{}';

  @ApiProperty({ description: '问卷类型', example: SurveyType.SURVEY, enum: SurveyType })
  @IsEnum(SurveyType)
  @IsOptional()
  surveyType: SurveyType = SurveyType.SURVEY;
}
